<template>
  <el-form
    :model="ruleForm"
    :rules="rules"
    ref="ruleForm"
    label-width="100px"
    class="demo-ruleForm"
  >
    <el-form-item label="姓名" prop="name">
      <el-input v-model="ruleForm.name"></el-input>
    </el-form-item>
    <el-form-item label="性别" prop="sex">
      <el-select v-model="ruleForm.sex" placeholder="请选择性别">
        <el-option label="男" value="男"></el-option>
        <el-option label="女" value="女"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="手机号码" prop="tel">
      <el-input v-model="ruleForm.tel"></el-input>
    </el-form-item>
    <el-form-item label="详细地址" required>
      <el-col :span="11">
        <el-form-item prop="value">
          <el-cascader
            v-model="ruleForm.value"
            :options="options"
            :props="{ expandTrigger: 'hover' }"
            style="width: 100%"
            class="btnLeft cascader"
          ></el-cascader>
        </el-form-item>
      </el-col>
      <!-- <el-col class="line" :span="2">-</el-col> -->
      <el-col :span="11">
        <el-form-item prop="address">
          <el-input v-model="ruleForm.address"></el-input>
        </el-form-item>
      </el-col>
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm')"
        >立即创建</el-button
      >
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        name: "",
        sex: "",
        tel: "",
        value: [],
        address: "",
      },
      rules: {
        name: [
          { required: true, message: "请输入姓名", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        sex: [{ required: true, message: "请选择性别", trigger: "change" }],
        tel: [
          { required: true, message: "请输入正确的手机号", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        value: [
          {
            required: true,
            message: "请选择日期",
            trigger: "change",
          },
        ],
        address: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
          { min: 1, message: "至少输入 1 个字符", trigger: "blur" },
        ],
      },
      options: [
        {
          value: "广东省",
          label: "广东省",
          children: [
            {
              value: "广州市",
              label: "广州市",
              children: [
                {
                  value: "番禺区",
                  label: "番禺区",
                },

                {
                  value: "越秀区",
                  label: "越秀区",
                },
                {
                  value: "花都区",
                  label: "花都区",
                },
                {
                  value: "海珠区",
                  label: "海珠区",
                },
                {
                  value: "从化区",
                  label: "从化区",
                },
                {
                  value: "增城区",
                  label: "增城区",
                },
                {
                  value: "南沙区",
                  label: "南沙区",
                },
                {
                  value: "黄埔区",
                  label: "黄埔区",
                },
                {
                  value: "白云区",
                  label: "白云区",
                },
                {
                  value: "天河区",
                  label: "天河区",
                },
                {
                  value: "荔湾区",
                  label: "荔湾区",
                },
              ],
            },
          ],
        },
      ],
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert("submit!");
          console.log(this.ruleForm);
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style></style>
